import numpy as np
import matplotlib.pyplot as plt
from data_reading_module import read_matern_cluster_data
from circle_radius_calculation_module import calculate_circle_radius
from circle_filtering_module import filter_points_in_circle
from dbscan_clustering_module import perform_dbscan_clustering
from cluster_sets_processing_module import process_cluster_sets
from plotting_module import plot_matern_cluster_process


def main():
    # 设置参数
    center = (0, 0)  # 圆形区域中心坐标
    radius = 20  # 圆形区域半径
    num_clusters = 20  # 母点（簇中心）数量
    file_path = "matern_cluster_data.pkl"  # 数据文件路径

    # 读取数据
    points, parent_points_x, parent_points_y = read_matern_cluster_data(file_path)

    # 计算半径
    radius_w = calculate_circle_radius(points, center)

    # 筛选在圆内的点
    in_circle = filter_points_in_circle(points, center, radius_w)

    # 进行 DBSCAN 聚类
    points_for_clustering = points[~in_circle]
    clusters = perform_dbscan_clustering(points_for_clustering)

    # 处理簇点集
    cluster_sets_for_draw, cluster_sets = process_cluster_sets(
        points, in_circle, clusters
    )

    # 创建图形
    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 8))

    # 绘制第一个子图
    plot_matern_cluster_process(
        ax1,
        points,
        center,
        radius_w,
        in_circle,
        cluster_sets_for_draw,
        cluster_sets,
        parent_points_x,
        parent_points_y,
        num_clusters,
        radius,  # 将 radius 作为参数传递给函数
    )

    # 绘制第二个子图
    plot_matern_cluster_process(
        ax2,
        points,
        center,
        radius_w,
        in_circle,
        cluster_sets_for_draw,
        cluster_sets,
        parent_points_x,
        parent_points_y,
        num_clusters,
        radius,  # 将 radius 作为参数传递给函数
    )

    plt.show()


if __name__ == "__main__":
    main()
